15. Extracting Indices
Extracting Indices
With RANSAC you identified which indices in your point cloud correspond to the table. If you applied the Pass Through Filter correctly, then the indices not corresponding to the table are those representing the objects on the table!
As the name suggests, the ExtractIndices Filter allows you to extract points from a point cloud by providing a list of indices. With the RANSAC fitting you just performed, the output inliers
corresponds to the point cloud indices that were within max_distance
of the best fit model.
While this filter does not perform any advanced filtering action, it is frequently used along with other techniques to obtain a subset of points from an input point cloud. Most object recognition algorithms return a set of indices associated with the points that form the identified target object.
As a result, it's convenient to use the ExtractIndices Filter to extract the point cloud associated with the identified object. To do this, add the following code to the Extract Inliers section of your RANSAC.py
script:
# Extract inliers
extracted_inliers = cloud_filtered.extract(inliers, negative=False)
filename = 'extracted_inliers.pcd'
pcl.save(extracted_inliers, filename)
Extract Inliers
SOLUTION:
0.01Object Extraction
While it's exciting to have successfully fit the plane of the table using RANSAC and extracted the subset of points corresponding to the table itself using the ExtractIndices Filter, we actually just want to get rid of the table and focus on the objects on top of the table.
It's easy to use what you've done already to extract all the objects of interest from the point cloud by simply changing the negative
flag on the extract
method to True
. Add the following code to the Extract Outliers section of your RANSAC.py
script to retrieve the subset of points for everything that did not fit the RANSAC model:
extracted_outliers = cloud_filtered.extract(inliers, negative=True)
filename = 'extracted_outliers.pcd'
pcl.save(extracted_outliers, filename)